package common.hua.com.mycontrolactivity;


import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.hua.common.BaseActivity;
import com.hua.common.commonview.ArcControl;

import common.hua.com.myapplication.R;

/**
 * 码表控件测试界面
 * @author huaxiaolin_pc
 *
 */
public class ArcActivity extends BaseActivity implements OnClickListener {

	private ArcControl percentageRing1 = null;
	private ArcControl percentageRing2 = null;
	private Button startBt = null;
	private Button stopBt =null;
	private Button resetBt=null;
	private TextView tv=null;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewItem(R.layout.arcactivitylayout);
		this.initViews();
		this.setPageTitle("码表");
	}

	private void initViews() {
		this.tv=(TextView) this.findViewById(R.id.text);
		percentageRing1 = (ArcControl) this.findViewById(R.id.round1);
		percentageRing2 = (ArcControl) this.findViewById(R.id.round2);
		this.startBt = (Button) this.findViewById(R.id.startbt);
		this.startBt.setOnClickListener(this);
		this.stopBt=(Button) this.findViewById(R.id.stopbt);
		this.stopBt.setOnClickListener(this);
		this.resetBt=(Button) this.findViewById(R.id.resetbt);
		this.resetBt.setOnClickListener(this);
		percentageRing2.setChangerListener(new ArcControl.RoundChangeListener() {
			@Override
			public void onchanged(float ratio) {
				tv.setText((int)(ratio*100)+"");
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.startbt:
				this.start();
				break;
			case R.id.stopbt:
				percentageRing1.cancle();
				percentageRing2.cancle();
				break;
			case R.id.resetbt:
				percentageRing2.reset();
				break;
		}
	}


	private void start(){
		percentageRing1.setColorList(new int[] { Color.parseColor("#FFFF0000"),
				Color.parseColor("#FFBF00"), Color.parseColor("#c000ff00"),
				Color.parseColor("#0085cf") });
		percentageRing1.setPercentage(50);
		percentageRing1.start();

		percentageRing2.setColorList(new int[] { Color.parseColor("#FFFF0000"),
				Color.parseColor("#FFBF00"), Color.parseColor("#c000ff00"),
				Color.parseColor("#0085cf") });
		percentageRing2.setPercentage(0);
		percentageRing2.start();
	}

}
